home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 03 / camtest.pas < prev    next >
Pascal/Delphi Source File  |  1991-04-16  |  3KB  |  105 lines

  1. program CAMTest;
  2.  
  3. { This program performs a simple test to see what SCSI devices are
  4.   attached to an MS-DOS machine with a CAM driver. The CAM unit tests
  5.   for the presence of CAM automatically. This program then performs
  6.   a Path Inquiry command -- which verifies that a SCSI bus exists and
  7.   that the program has allocated sufficient buffer space. It then
  8.   sends a series of Device Inquiry commands to each of the 8 possible
  9.   SCSI device addresses and reports what it finds. The CAM unit provides
  10.   an object-oriented framework for this process and hides most of its
  11.   complexity. }
  12.  
  13. { Copyright (C) 1991 by Brett Glass, All Rights Reserved.
  14.   Original program concept from BallardSynergy CAM Developer's
  15.    Toolkit, Copyright (C) 1990 by BallardSynergy, All Rights Reserved.
  16.    Used with permission. }
  17.  
  18. uses CAM;
  19.  
  20. var
  21.   pathInq : PathInquiryCCB; {CCB for path inquiry request}
  22.   scsiReq : SCSIRequestCCB; {CCB for SCSI I/O requests}
  23.   inqBuf  : array [0..31] of Byte; {Buffer for data returned by inquiry}
  24.   id : Byte; {SCSI ID loop counter}
  25.   i : Integer; {Temporary character counter}
  26.  
  27. procedure WriteDevType(d : Byte);
  28. { Write the type of device that's associated with a number, according
  29.   to the SCSI spec }
  30. begin
  31. case d of
  32.   0 : Write('Disk');
  33.   1 : Write('Tape');
  34.   2 : Write('Printer');
  35.   4 : Write('WORM')
  36. else
  37.   Write('Unknown')
  38.   end;
  39. end;
  40.  
  41.  
  42. begin {Main Program}
  43. {Doing a Path Inquiry is as simple as invoking two methods.}
  44. with pathInq do
  45.   begin
  46.   Init; {Set all fields to their default values}
  47.   Submit; {Submit the CCB for processing}
  48.   {Wait for completion; pro forma on single-tasking systems like MS-DOS}
  49.   while camStatus = STAT_REQUEST_IN_PROGRESS do;
  50.   if camStatus <> STAT_REQUEST_DONE_NO_ERROR then
  51.     begin
  52.     Writeln('Path Inquiry returned error ', pathInq.camStatus);
  53.     Halt;
  54.     end;
  55.   if privateDataSize > SCSI_REQUEST_FILL_SIZE then
  56.     begin
  57.     Writeln('Error: CCB not big enough to allow SCSI requests');
  58.     Halt;
  59.     end;
  60.   end;
  61. Writeln;
  62. Writeln('SCSI Device Report');
  63. Writeln('------------------');
  64. for id := 0 to 7 do {Loop over all 8 SCSI ids}
  65.   begin
  66.   with scsiReq do
  67.     begin
  68.     Init;
  69.     camFlags := CAM_DIR_DATA_IN; {We're receiving data}
  70.     targetID := id; {From this device}
  71.     cdbLength := 6; {We're sending 6 bytes of command}
  72.     dataLength := 32; {And receiving 32}
  73.     dataPtr := @inqBuf; {In this buffer}
  74.     cdb[0] := $12; {Inquiry command}
  75.     cdb[4] := 32; {Maximum size of buffer}
  76.  
  77.     Submit; {Submit the request}
  78.  
  79.     while camStatus = STAT_REQUEST_IN_PROGRESS do; {Wait for completion}
  80.     {Report the results}
  81.     Write(id, ': ');
  82.     case camStatus of
  83.       STAT_REQUEST_DONE_NO_ERROR:
  84.         begin
  85.         {There's a device there; say what kind it is and show its ID string}
  86.         WriteDevType(inqBuf[0]);
  87.         Write(' -- ');
  88.         {Write string returned by inquiry}
  89.         for i := 8 to 32 do
  90.           Write(Char(inqBuf[i]));
  91.         Writeln;
  92.         end;
  93.       STAT_SELECTION_TIMEOUT:
  94.         Writeln('No device present');
  95.       STAT_SCSI_BUS_BUSY:
  96.         Writeln('Device busy');
  97.       STAT_INVALID_TARGET_ID:
  98.         Writeln('Host')
  99.     else
  100.       Writeln('** ERROR **')
  101.       end;
  102.     end;
  103.   end;
  104. end.
  105.